home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1990: Discy Business / Discy Business.2mg / DEV.CD / TOOLS / SAMPLES / HP / HP.PAS / GLOBALS.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1987-08-13  |  10.4 KB  |  247 lines  |  [B0] Apple IIgs Source Code (0x001E)

  1. UNIT Globals;
  2.  
  3. {+----------------------------------------------------------------------------+
  4.  |                                                                            |
  5.  |         HodgePodge:  An example Apple IIGS Desktop application             |
  6.  |                                                                            |
  7.  |    Written in 65816 assembler and APW C by the Apple IIGS Tools Team       |
  8.  |              Translated to TML Pascal by TML Systems, Inc.                 |
  9.  |  Modified by Ben Koning for "Programmer's Introduction to the Apple IIGS"  |
  10.  |                                                                            |
  11.  |             Copyright (c) 1986-87 by Apple Computer, Inc.                  |
  12.  |                Copyright (c) 1987 by TML Systems, Inc.                     |
  13.  |                                                                            |
  14.  |                     --------------------------------                       |
  15.  |                                                                            |
  16.  |     Pascal UNIT "GLOBALS.PAS" : Global data structs and init routine       |
  17.  |                                                                            |
  18.  +----------------------------------------------------------------------------+}
  19.  
  20.  
  21.  
  22. INTERFACE
  23.  
  24. USES
  25.        HPIntfData,         {HodgePodge Apple IIGS Toolbox Interface Units}
  26.        HPIntfProc,
  27.        HPIntfPdos;
  28.  
  29. CONST
  30.        ScreenMode        = $80;   {640 mode}
  31.        MaxX              = 640;   {Max X clamp (should correspond to ScreenMode}
  32.        MaxScan           = 160;   {Max size of scan line}
  33.  
  34.        AppleMenuID       = 300;
  35.            AboutItem     = 301;
  36.        FileMenuID        = 400;
  37.            OpenItem      = 401;
  38.            CloseItem     = 255;   {For DA's}
  39.            SaveAsItem    = 403;
  40.            ChoosePItem   = 405;
  41.            PageSetItem   = 406;
  42.            PrintItem     = 407;
  43.            QuitItem      = 409;
  44.        EditMenuID        = 500;
  45.            UndoItem      = 250;    {For DA's}
  46.            CutItem       = 251;    {For DA's}
  47.            CopyItem      = 252;    {For DA's}
  48.            PasteItem     = 253;    {For DA's}
  49.            ClearItem     = 254;    {For DA's}
  50.        WindowsMenuID     = 600;
  51.            NoWindowsItem = 601;
  52.            FirstWindItem = 2000;   {Allocated dynamically starting at 2000}
  53.        FontsMenuID       = 700;
  54.            FontItem      = 701;
  55.            MonoItem      = 702; 
  56.  
  57.        FirstWind         = 0;      {Lower bound of WindowList}
  58.        LastWind          = 15;     {Upper bound of WindowList}
  59.  
  60.  
  61.  
  62. TYPE
  63.        WindDataH   = ^WindDataP;           {RefCon data for our windows}
  64.        WindDataP   = ^WindDataRec;         {...carried along with wind data}
  65.        WindDataRec = record
  66.                        Name:    Str255;
  67.                        MenuStr: Str255;
  68.                        MenuID:  integer;
  69.                        Flag:    integer;           {0 = Paint, 1 = Font}
  70.                        case integer of
  71.                            0      : (theFont: FontID;
  72.                                      isMono :  boolean);
  73.                            1      : (pict:    Handle);
  74.                      end;
  75.  
  76.  
  77.  
  78. VAR
  79.        MyMemoryID    : integer;      {Application ID assigned by Memory Mgr}
  80.        Done          : boolean;      {True when quitting}
  81.        ToolsZeroPage : Handle;       {Handle to Zero page memory for Tools}
  82.        Event         : WmTaskRec;    {All events are returned here}
  83.  
  84.        AppleMenuStr  : Str255;       {For creating menus}
  85.        FileMenuStr   : Str255;
  86.        EditMenuStr   : Str255;
  87.        WindowMenuStr : Str255;
  88.        FontMenuStr   : Str255;
  89.  
  90.        NoWindStr     : String [40];  {Menu Item String for "No Windows..."}
  91.        MonoStr       : String [40];
  92.        ProStr        : String [40];
  93.  
  94.        LastWindow    : GrafPortPtr;  {The Front Window last time through event l
  95.        dummy         : integer;      {*** >!< Possible compiler bug?}
  96.        DesiredFont   : FontID;       {Indicates current selected font}
  97.        isMonoFont    : boolean;      {Flag indicates if mono spacing selected}
  98.        myReply       : SFReplyRec;
  99.        PictHndl      : Handle;
  100.  
  101.        WIndex        : integer;      {Count of number of windows open}
  102.        WindowList    :               {List of up to 15 open windows}
  103.                        array [firstWind..lastWind] of GrafPortPtr;
  104.  
  105.        PlsWtTemp     : DialogTemplate;
  106.        PlsWtItem     : ItemTemplate;
  107.  
  108.        AppleIcon     : record
  109.                            boundsRect : Rect;
  110.                            data       : array [1..34] of 
  111.                                            packed array [1..16] of byte;
  112.                        end;
  113.  
  114.  
  115.  
  116. procedure InitGlobals;                                     {Setup variables}
  117. PROCEDURE HPStuffHex (thingPtr : Ptr; s : Str255);         {Store hex}
  118.  
  119.  
  120.  
  121.  
  122.  
  123. IMPLEMENTATION
  124.  
  125.  
  126.  
  127. PROCEDURE HPStuffHex (thingPtr : Ptr; s : Str255);
  128.  
  129.    {>!< This routine will be implemented in TML Pascal V1.1.  For now,
  130.     we define it ourselves.  StuffHex stores bytes (expressed as a string
  131.     of hexadecimal digits) into any data structure, and is based on the
  132.     StuffHex procedure in Macintosh QuickDraw.  The resolution of this
  133.     routine is on byte boundaries.}
  134.  
  135.    var Iterator    : integer;
  136.        StringIndex : integer;
  137.  
  138.    begin   {of HPStuffHex}
  139.        for Iterator := 0 to Length (s) - 1 do begin
  140.            StringIndex := (Iterator * 2) + 1;
  141.            thingPtr^ := Hex2Int (StringPtr (longint (@s) + StringIndex),2);
  142.            thingPtr := pointer (longint (thingPtr) + 1);
  143.        end;
  144.    end;    {of HPStuffHex}
  145.  
  146.  
  147.  
  148.  
  149.  
  150. procedure InitGlobals;
  151.  
  152.    {Initialize global data variables, including the PlsWtTemp used by
  153.     ShowPleaseWaitDialog, the menu strings used by the menu bar setup
  154.     routines in MENU.PAS, and the apple icon used by the "about..."
  155.     item dialog routine in DIALOG.PAS}
  156.  
  157.    begin   {of InitGlobals}
  158.        with PlsWtTemp do begin
  159.            SetRect    (dtBoundsRect,120,30,520,80);
  160.            dtVisible  := true;
  161.            dtRefCon   := 0;
  162.            dtItemList [0] := pointer (0); {We will insert ptr to item here}
  163.            dtItemList [1] := nil;         {Null-terminated}
  164.        end;
  165.  
  166.        AppleMenuStr := concat ('>>@\N300X\0',
  167.                                '==About HodgePodge...\N301\0',
  168.                                '==-\N302D\0.');
  169.        FileMenuStr  := concat ('>>  File  \N400\0',
  170.                                '==Open...\N401*Oo\0',
  171.                                '==Close\N255D\0',
  172.                                '==Save As...\N403D\0',
  173.                                '==-\N404D\0',
  174.                                '==Choose Printer...\N405\0',
  175.                                '==Page Setup...\N406D\0',
  176.                                '==Print...\N407*PpD\0',
  177.                                '==-\N408D\0',
  178.                                '==Quit\N409*Qq\0.');
  179.        EditMenuStr  := concat ('>>  Edit  \N500D\0',
  180.                                '==Undo\N250*Zz\0',
  181.                                '==-\N501D\0',
  182.                                '==Cut\N251*Xx\0',
  183.                                '==Copy\N252*Cc\0',
  184.                                '==Paste\N253*Vv\0',
  185.                                '==Clear\N254\0.');
  186.        WindowMenuStr := concat('>>  Window  \N600D\0',
  187.                                '== No Windows Allocated\N601D\0.');
  188.        FontMenuStr   := concat ('>>  Fonts  \N700\0',
  189.                                '==Display Font...\N701*Ff\0',
  190.                                '==Display Font as Mono-spaced\N702*Mm\0.');
  191.  
  192.        LastWindow    := nil;
  193.  
  194.        NoWindStr     := '==No Windows Allocated\N601D\0.';
  195.    
  196.        MonoStr       := '=Display Font as Mono-spaced';
  197.        ProStr        := '=Display Font as Proportional';
  198.        isMonoFont    := false;
  199.  
  200.        with DesiredFont do begin
  201.            famNum    := $FFFE;
  202.            fontStyle := 0;
  203.            fontSize  := 8;
  204.        end;
  205.  
  206.        WIndex := 0;                    {No windows open yet}
  207.  
  208.        SetRect    (AppleIcon.boundsRect,0,0,64,34);
  209.        HPStuffHex (@AppleIcon.data[1], '00000000000000000000000000000000');
  210.        HPStuffHex (@AppleIcon.data[2], '0FFFFFFFFFFFFFFFFFFFFFFFFFFFFFF0');
  211.        HPStuffHex (@AppleIcon.data[3], '0F0000000000000000000000000000F0');
  212.        HPStuffHex (@AppleIcon.data[4], '0F0FFFFFFFFFFFFFFFFFFFFFFFFFF0F0');
  213.        HPStuffHex (@AppleIcon.data[5], '0F0FFFFFFFFFFFFFFFFFF88FFFFFF0F0');
  214.        HPStuffHex (@AppleIcon.data[6], '0F0FFFFFFFFFFFFFFFF8888FFFFFF0F0');
  215.        HPStuffHex (@AppleIcon.data[7], '0F0FFFFFFFFFFFFFFF88888FFFFFF0F0');
  216.        HPStuffHex (@AppleIcon.data[8], '0F0FFFFFFFFFFFFFF88888FFFFFFF0F0');
  217.        HPStuffHex (@AppleIcon.data[9], '0F0FFFFFFFFFFFFF888888FFFFFFF0F0');
  218.        HPStuffHex (@AppleIcon.data[10],'0F0FFFFFFFFFFFFF88888FFFFFFFF0F0');
  219.        HPStuffHex (@AppleIcon.data[11],'0F0FFFFFFFFFFFFF8888FFFFFFFFF0F0');
  220.        HPStuffHex (@AppleIcon.data[12],'0F0FFFFFF8888FFF88FF8888FFFFF0F0');
  221.        HPStuffHex (@AppleIcon.data[13],'0F0FFFF88888888FFF88888888FFF0F0');
  222.        HPStuffHex (@AppleIcon.data[14],'0F0FFF888888888888888888888FF0F0');
  223.        HPStuffHex (@AppleIcon.data[15],'0F0FFeeeeeeeeeeeeeeeeeeeeFFFF0F0');
  224.        HPStuffHex (@AppleIcon.data[16],'0F0FFeeeeeeeeeeeeeeeeeeeFFFFF0F0');
  225.        HPStuffHex (@AppleIcon.data[17],'0F0FFeeeeeeeeeeeeeeeeeeFFFFFF0F0');
  226.        HPStuffHex (@AppleIcon.data[18],'0F0FF666666666666666666FFFFFF0F0');
  227.        HPStuffHex (@AppleIcon.data[19],'0F0FF666666666666666666FFFFFF0F0');
  228.        HPStuffHex (@AppleIcon.data[20],'0F0FF666666666666666666FFFFFF0F0');
  229.        HPStuffHex (@AppleIcon.data[21],'0F0FF4444444444444444444FFFFF0F0');
  230.        HPStuffHex (@AppleIcon.data[22],'0F0FF44444444444444444444FFFF0F0');
  231.        HPStuffHex (@AppleIcon.data[23],'0F0FFF444444444444444444444FF0F0');
  232.        HPStuffHex (@AppleIcon.data[24],'0F0FFF555555555555555555555FF0F0');
  233.        HPStuffHex (@AppleIcon.data[25],'0F0FFF555555555555555555555FF0F0');
  234.        HPStuffHex (@AppleIcon.data[26],'0F0FFFF5555555555555555555FFF0F0');
  235.        HPStuffHex (@AppleIcon.data[27],'0F0FFFF1111111111111111111FFF0F0');
  236.        HPStuffHex (@AppleIcon.data[28],'0F0FFFFF11111111111111111FFFF0F0');
  237.        HPStuffHex (@AppleIcon.data[29],'0F0FFFFFF111111FFF111111FFFFF0F0');
  238.        HPStuffHex (@AppleIcon.data[30],'0F0FFFFFFF1111FFFFF1111FFFFFF0F0');
  239.        HPStuffHex (@AppleIcon.data[31],'0F0FFFFFFFFFFFFFFFFFFFFFFFFFF0F0');
  240.        HPStuffHex (@AppleIcon.data[32],'0F0000000000000000000000000000F0');
  241.        HPStuffHex (@AppleIcon.data[33],'0FFFFFFFFFFFFFFFFFFFFFFFFFFFFFF0');
  242.        HPStuffHex (@AppleIcon.data[34],'00000000000000000000000000000000');
  243.  
  244.    end;    {of InitGlobals}
  245.  
  246. END.
  247.